package com.example.safe.keyboard;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.safe.keyboard.databinding.ActivityLetterNumberBinding;
import com.surfin.safe.keyboard.SafeKeyboard;
import com.surfin.safe.keyboard.SafeKeyboardConfig;

public class LetterNumberActivity extends AppCompatActivity {

    public static void start(Context context) {
        context.startActivity(new Intent(context, LetterNumberActivity.class));
    }

    private SafeKeyboard safeKeyboard;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityLetterNumberBinding binding = ActivityLetterNumberBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        setTitle(R.string.keyboard_letter_number);
        // 配置软键盘
        SafeKeyboardConfig config = SafeKeyboardConfig.getDefaultConfig();
        // 字母键盘带数字
        config.letterWithNumber = true;
        // 键盘标题和颜色
        config.keyboardTitle = "安全键盘字母带数字";
        config.keyboardTitleColor = R.color.C_218AFF;
        // 键盘图标
        config.keyboardShieldImgResId = R.drawable.app_shield;
        safeKeyboard = new SafeKeyboard(this, binding.ctlKeyboardContainer,
                binding.ctlRoot, config);
        safeKeyboard.putRandomEdit(binding.etLetterNumber);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (safeKeyboard != null) {
            safeKeyboard.release();
            safeKeyboard = null;
        }
    }
}
